local mengfen = fk.CreateSkill {
  name = "ls__mengfen",
}

Fk:loadTranslationTable{
  ["ls__mengfen"] = "猛奋",
  ["@@mengfen-turn"] = "猛奋",
  [":ls__mengfen"] = "当你使用【杀】指定目标后，你可依次重铸至多三张牌，若你以此法重铸：【闪】，此【杀】不可被响应；黑桃牌，你弃置目标角色一张牌；三种类别的牌，"..
  "此【杀】不计入次数限制，且若你于此回合使用的下一张牌为锦囊牌，也可发动“猛奋”。",
  ["#ls__mengfen-invoke"] = "你可以对%src发动“猛奋”",
  ["#ls__mengfen-recast"] = "猛奋：你可以重铸一张牌",

  ["$ls__mengfen1"] = "乘胜追击，杀！杀！",
  ["$ls__mengfen2"] = "驰骋沙场，杀敌无惧。",
}

local ls = require "packages/lvshi/utility"

mengfen:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(mengfen.name) and target == player and not player:isNude() then
      return data.card.trueName == "slash" or (data.card.type == Card.TypeTrick and player:getMark("@@mengfen-turn") > 0)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@mengfen-turn", 0)
    local cards = {}
    for i = 1, 3, 1 do
      local card = player.room:askToCards(player, {
        min_num = 1,
        max_num = 1,
        skill_name = mengfen.name,
        include_equip = true,
        pattern = ".",
        prompt = "#ls__mengfen-recast",
        cancelable = true,
      })
      if #card == 0 then break end
      table.insertIfNeed(cards, card[1])
      room:recastCard(card, player, self.name)
    end
    if table.find(cards, function(id) return Fk:getCardById(id).trueName == "jink" end) then
      data.disresponsive = true
    end
    if table.find(cards, function(id) return Fk:getCardById(id).suit == Card.Spade end) and not data.to:isNude() then
      local id = room:askToChooseCard(player, { target = data.to, flag = "he", skill_name = mengfen.name })
      room:throwCard({id}, mengfen.name, data.to, player)
    end
    if ls.countTypes(cards) == 3 then
      room:addPlayerMark(player, "@@mengfen-turn")
      player:addCardUseHistory(data.card.trueName, -1)
      data.extraUse = true
    end
  end,
})

return mengfen